﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ActionServices;
using CoreData;
using Helper;

namespace ZidoniCMS.Controllers
{
    public class MenuController : BaseController
    {
        //
        // GET: /Menu/
        public MenuController(IMenuActionService _menu, IConfigurationActionService _config, ICategoryActionService _category, ICategoryArticleActionService _categoryarticle, IProductActionService _product)
            :base(_menu, _config, _category, _categoryarticle, _product)
        {}        
        
        /// <summary>
        /// Menu on top header
        /// </summary>
        /// <returns></returns>
        public ActionResult _TopMenu()
        {
            var dataParent = CategoryService.GetListByLINQ(x => x.Active == true && x.ParentID == 0);
            if (dataParent.Count() > 0)
            {
                string str = "";
                str += "<div class='top-menu'><ul class='list-nav'>";
                str += @"<li><a class='link-parent' href='" + Url.Action("Index", "Home") + "'>Trang chủ</a></li>";
                str += @"<li><a class='link-parent' href='" + Url.RouteUrl("product_list") + "'>Sản phẩm</a></li>";
                str += @"<li><a class='link-parent' href='" + Url.RouteUrl("articles_list") + "'>Bài viết</a></li>";
                foreach (var item in dataParent)
                {
                    str += @"<li><a class='link-parent' href='" + Url.RouteUrl("category_list", new { Id = item.ID, Link = item.Link }) + "'>" + item.Name + "</a> ";
                    var childData = CategoryService.GetListByLINQ(x => x.ParentID == item.ID);
                    if (childData.Count > 0)
                    {
                        str += @"<div class='child-menu'><div class='arrow-up'>
                                </div><ul>";
                        foreach (var child in childData)
                        {
                            str += "<li><a href='" + Url.RouteUrl("category_list", new { Id = child.ID, Link = child.Link }) + "'>" + child.Name + "</a> </li>";
                        }
                        str += "</ul></div>";
                    }
                    str += "</li>";
                }
                str += "</ul></div>";
                ViewBag.dataMenu = str;
            }
            return PartialView();
        }
        /// <summary>
        /// Topbar
        /// </summary>
        /// <returns></returns>
        public ActionResult _TopBar() {
            return PartialView();
        }
    }
}
